//
//  Seach_SearchResult_Tbv_WX.m
//  ZITHER
//
//  Created by weixin on 2019/3/28.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Seach_SearchResult_Tbv_WX.h"
#import "GoodsModel.h"
#import "InquiryMain_HotGoodsList_Cell_WX.h"
#import "STViewController.h"
#import "Seach_Filtrate_Model_WX.h"

@implementation Seach_SearchResult_Tbv_WX

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        [self Starefreshing];
        self.backgroundColor = HexColor(0xf5f5f5);
        
    }
    return self;
}

-(void)setType:(NSInteger)type{
    _type = type;
    [self.mj_header beginRefreshing];
}

-(void)Starefreshing{
    
    [[serviceDefualt loadSeachGoodsList:kUSER_Filtrate_MANAGER.arrBrandSelect page:self.page sort:kUSER_Filtrate_MANAGER.SearchResultTopBarModel.sotr keyword:kUSER_Filtrate_MANAGER.SearchResultTopBarModel.keyWord reponseObjctClass:nil]subscribeNext:^( ResponseData * x) {
        if (x.success) {
            
            NSArray *arr = x.responseRawData[@"data"][@"goodVOs"];
            NSLog(@"%@",x.responseRawData[@"data"][@"totalCount"]);
            
//            kUSER_Filtrate_MANAGER.SearchResultTopBarModel = [[Seach_SearchResultTopBar_Model_WX alloc]init];

            int officialPriceeInt = [x.responseRawData[@"data"][@"totalCount"] intValue];
            kUSER_Filtrate_MANAGER.SearchResultTopBarModel.ResultCont = x.responseRawData[@"data"][@"totalCount"];

//            NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
//            moneyFormatter.positiveFormat = @"###,##0";
//            NSString *formatString = [moneyFormatter stringFromNumber:@(officialPriceeInt)];
            [self setNoMoreDataBg:YES NoDataState:NoMoreDataStateDefault];

            if (arr.count == 0) {
                if (self.page == 0 ) {
                    [self setNoMoreDataBg:NO NoDataState:NoMoreDataStateDefault];
                    self.noMoreDateView.title.text = @"暂无更多此表款";
//                    [Tools showTips:@"暂无更多数据"];
                    [self endRefreshing];
                }else{
                    [self.mj_footer endRefreshingWithNoMoreData];
                }
                return ;
                
            }else{
                if (self.page == 0) {
                    self.arrM = [[NSMutableArray alloc]init];
                }
                for (NSDictionary *dic in  arr) {
                    goodVOsModel *model = [goodVOsModel yy_modelWithJSON:dic];
                    [self.arrM addObject:model];
                }
            }
            
            [self reloadData];
        }else{
            [Tools showTips:x.errorInfo];
        }
        [self endRefreshing];
    }];
    
    /*
     //获取热门个数据
     [[serviceDefualt loadGoodsHotList:self.page index:self.type reponseObjctClass:[GoodsModel class]]subscribeNext:^(ResponseData *x) {
     if (x.success) {
     
     NSArray *arr = x.responseRawData[@"data"][@"goodVOs"];
     
     if (arr.count == 0) {
     if (self.page == 0 ) {
     [self setNoMoreDataBg:NO NoDataState:NoMoreDataStateDefault];
     [Tools showTips:@"暂无更多数据"];
     [self endRefreshing];
     }else{
     [self.mj_footer endRefreshingWithNoMoreData];
     }
     return ;
     
     }else{
     if (self.page == 0) {
     self.arrM = [[NSMutableArray alloc]init];
     }
     for (NSDictionary *dic in  arr) {
     goodVOsModel *model = [goodVOsModel yy_modelWithJSON:dic];
     [self.arrM addObject:model];
     }
     }
     
     [self reloadData];
     }else{
     [Tools showTips:x.errorInfo];
     }
     [self endRefreshing];
     }];
     */

    
}

#pragma mark -- tabdelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrM.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    goodVOsModel * model =  self.arrM[indexPath.row];
    static NSString *sectionCell = @"InquiryMain_HotGoodsList_Cell_WX";
    InquiryMain_HotGoodsList_Cell_WX * cell = [tableView dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[InquiryMain_HotGoodsList_Cell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.State = 1;
    cell.model = model;
    return cell;
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    goodVOsModel * model =  self.arrM[indexPath.row];
    STViewController *vc = [[STViewController alloc]init];
    vc.type = STControllerTypeHiddenNavBar;
    vc.goodId = model.goodInfo.id;
    [self.getNav pushViewController:vc animated:YES];
    
}



- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}


@end
